package com.contact;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;

import com.android.ocean.util.common.StringUtil;
import com.common.method.ServerPath;
import com.google.android.imageloader.ImageLoader;
import com.http.UserInfoTask;
import com.matang.R;
import com.modle.User;
import com.util.AppUtil;
import com.util.OUtil;
import com.view.XJobSigleOrgCurrentView;
import com.view.XJobSigleOrgHistoryView;

/**
 * 
 * @author Zhuw机构信息
 * 
 */
public class OrgInfoActivity extends BaseActivity implements OnClickListener,
UserInfoTask.CallBack {
	RadioGroup radioGroup;
	FrameLayout container;
	View jjView;
	TextView titleTv, addressTv, permitTv, descTv;
	ImageView thumbIv,bgIv;

	View currentView;
	XJobSigleOrgCurrentView currentListView;
	View zphiswView;
	XJobSigleOrgHistoryView hisListView;

	String userID;
	User user;
	@Override
	protected void onCreate(Bundle savedInstanceState) {

		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.act_org_info);
		init();
	}

	void init() {
		mContext = OrgInfoActivity.this;
		findViews();
		initPaneData();

	}

	@Override
	protected void findViews() {
		super.findViews();
		container = (FrameLayout) findViewById(R.id.container);
		radioGroup = (RadioGroup) findViewById(R.id.radiogroup);
		radioGroup.setOnCheckedChangeListener(checkedChangeListener);

		jjView = LayoutInflater.from(mContext).inflate(
				R.layout.view_org_jj_noedit, null);
		titleTv = (TextView) jjView.findViewById(R.id.title_tv);
		addressTv = (TextView) jjView.findViewById(R.id.address_tv);
		permitTv = (TextView) jjView.findViewById(R.id.permit_id);
		descTv = (TextView) jjView.findViewById(R.id.desc_tv);
		thumbIv = (ImageView) jjView.findViewById(R.id.thumb_iv);
		bgIv = (ImageView) jjView.findViewById(R.id.bg_iv);
		currentView = LayoutInflater.from(mContext).inflate(
				R.layout.view_job_sigle_org_current_list, null);
		currentListView = (XJobSigleOrgCurrentView) currentView
				.findViewById(R.id.xXListView);

		zphiswView = LayoutInflater.from(mContext).inflate(
				R.layout.view_job_his_list, null);
		hisListView = (XJobSigleOrgHistoryView) zphiswView
				.findViewById(R.id.xXListView);

	}

	@Override
	public void initPaneData() {
		super.initPaneData();
		header.headTitleTv.setText("机构信息");
		userID = getIntent().getStringExtra("userID");
		container.addView(jjView);
		if (user == null) {
			loadUserInfo();
		}
		currentListView.initData(userID);
		hisListView.initData(userID);

	}

	void loadUserInfo() {
		showProgressDialog();
		new UserInfoTask(this).execute(userID);

	}

	void freshUserPane() {
		if (null!=user&&null!=user.orgInfo) {
			titleTv.setText("名称：" + user.orgInfo.title);
			addressTv.setText("地址：" + user.orgInfo.address);
			permitTv.setText(StringUtil.permitEncry(user.orgInfo.mainPermitID));
			descTv.setText(user.orgInfo.desc);
			 ImageLoader.get(mContext).bind(thumbIv,ServerPath.SERVER+user.thumb,
			 null,R.drawable.default_head);
			 OUtil.setThumbBg(user, bgIv);

		}

	}

	private OnCheckedChangeListener checkedChangeListener = new OnCheckedChangeListener() {

		@Override
		public void onCheckedChanged(RadioGroup group, int checkedId) {
			switch (checkedId) {
			case R.id.rd_jj:
				container.removeAllViews();
				container.addView(jjView);
				break;
			case R.id.rd_zbzw:
				container.removeAllViews();
				container.addView(currentView);
				break;
			case R.id.rd_zp_his:
				container.removeAllViews();
				container.addView(zphiswView);
				break;
			default:
				break;
			}
		}
	};

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		}

	}
//
//	@Override
//	public void procUserOrgInfo(UserOrgInfo data) {
//		dismissProgressDialog();
//		this.userOrgInfo = data;
//		fillPane();
//
//	}

	@Override
	public void procError(String msg) {
		dismissProgressDialog();
		AppUtil.tsMsg(mContext, msg);

	}

	@Override
	public void procUserInfoData(User data) {
		dismissProgressDialog();
		user = data;
		freshUserPane();

	}

	@Override
	public void procUserInfoError(String msg) {
		AppUtil.tsMsg(mContext, "获取机构信息失败：" + msg);
		finish();
	}

}
